<?php

namespace bc\controller;

use yii\rest\Controller;
use yii\web\Response;
use yii\filters\ContentNegotiator;
use yii\filters\VerbFilter;
use yii;

class ApiController extends Controller
{
	/**
	 * @inheritdoc
	 */
	public function behaviors()
	{
		return [
				'contentNegotiator' => [
						'class' => ContentNegotiator::className(),
						'formats' => [
								'application/json' => Response::FORMAT_JSON,
						],
				],
				'verbFilter' => [
						'class' => VerbFilter::className(),
						'actions' => $this->verbs(),
				],
		];
	}
	
		/**
	 * @inheritdoc
	 */
	public function behaviors()
	{
		return [
				'contentNegotiator' => [
						'class' => ContentNegotiator::className(),
						'formats' => [
								'application/json' => Response::FORMAT_JSON,
						],
				],
				'verbFilter' => [
						'class' => VerbFilter::className(),
						'actions' => $this->verbs(),
				],
		];
	}
	
	/**
	 * get请求参数
	 *
	 * @author gray.guo
	 * @param string $name
	 * @param mixed $defaultValue
	 * @return array|mixed
	 */
	public function get($name, $defaultValue = NULL)
	{
		return trim(Yii::$app->request->get ( $name, $defaultValue ));
	}
	
	/**
	 * post请求参数
	 *
	 * @author gray.guo
	 * @param string $name
	 * @param mixed $defaultValue
	 * @return array|mixed
	 */
	public function post($name, $defaultValue = NULL)
	{
		return trim(Yii::$app->request->post ( $name, $defaultValue ));
	}
	
	/**
	 *
	 * @author gray.guo
	 * @return yii\web\Request
	 */
	public function getRequest()
	{
		return Yii::$app->request;
	}
	
	/**
	 *
	 * @author gray.guo
	 * @return yii\web\Response
	 */
	public function response()
	{
		return Yii::$app->response;
	}
	
	/**
	 *
	 * @return array
	 */
	public function getParams()
	{
		return Yii::$app->request->getQueryParams ();
	}
	
	/**
	 *
	 * @param string $name
	 * @param string $defaultValue
	 * @return string
	 */
	public function getParam($name, $defaultValue = NULL)
	{
		return Yii::$app->request->getQueryParam ( $name, $defaultValue = NULL );
	}
}

